package com.example.yuejian23.yuejian_23.Adapter;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.yuejian23.yuejian_23.R;
import com.example.yuejian23.yuejian_23.activity.BisaiActivity;
import com.example.yuejian23.yuejian_23.activity.HuodongActivity;
import com.example.yuejian23.yuejian_23.javaBean.BisaiBean;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by dong on 2017/10/15.
 */

public class BisaiAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context mContext;
    private List mDataList;
    private LayoutInflater mlayoutInflater;
    public BisaiAdapter(Context mContext, List<BisaiBean> mDataList){
        this.mContext = mContext;
        this.mDataList = mDataList;
        mlayoutInflater = LayoutInflater.from(mContext);

    }
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = mlayoutInflater.from(parent.getContext()).inflate(R.layout.bisai, parent, false);
        return new BisaiAdapter.ViewHolder(v);
    }
    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        final BisaiBean entity = (BisaiBean) mDataList.get(position);
        if (null == entity)
            return;
        BisaiAdapter.ViewHolder viewHolder = (BisaiAdapter.ViewHolder) holder;
        viewHolder.name.setText(entity.getGname());
        Picasso.with(mContext).load("http://115.159.93.244/new18yuejian/Public/upload/"+entity.getGpic()).into(viewHolder.bisai_thumb);

        viewHolder.bisai_card.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                Bundle bundle = new Bundle();
                intent.setClass(mContext, BisaiActivity.class);

                bundle.putString("bisaiid",entity.getGid());
                intent.putExtras(bundle);
                mContext.startActivity(intent);
            }
        });
    }
    @Override
    public int getItemCount() {
        return mDataList.size();
    }
    private class ViewHolder extends RecyclerView.ViewHolder {
        TextView name;
        ImageView bisai_thumb;
        CardView bisai_card;

        public ViewHolder(View v) {
            super(v);
            name = (TextView) v.findViewById(R.id.name);
            bisai_thumb = (ImageView) v.findViewById(R.id.bisai_thumb);
            bisai_card = (CardView) v.findViewById(R.id.bisai_card);
        }
    }
}
